﻿using System;

namespace KryptecizerBase.Decryption
{
    /// <summary>
    /// Decryptor for TextBasedKryptOjects.
    /// </summary>
    public abstract class KryptoTextDecryptor : Decryptor
    {
        #region Member
        protected KryptoText _KryptoText;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the decrypted krypto text.
        /// </summary>
        /// <value>The decrypted krypto text.</value>
        public KryptoText DecryptedKryptoText
        {
            get { return _KryptoText; }
            set { _KryptoText = value; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="KryptoTextDecryptor"/> class.
        /// </summary>
        public KryptoTextDecryptor()
        {
            _KryptoText = new KryptoText();
        }
        #endregion

        #region public methods
        /// <summary>
        /// Implementation of abstract decryption method.
        /// Calls OnDecryptionStartet and OnDecryptionEnded methods.
        /// Uses abstract protected Decrypt method.
        /// </summary>
        public override void Decrypt()
        {
            OnDecryptionStartet();
            bool result = Decrypt(_KryptoText.Clone());
            OnDecryptionEnded(result);
        }
        #endregion

        #region abstract methods
        /// <summary>
        /// Abstract method to decrypt the specified krypto text.
        /// </summary>
        /// <param name="kryptoText">The krypto text.</param>
        /// <returns>success</returns>
        protected abstract bool Decrypt(KryptoText kryptoText);
        #endregion
    }
}
